<?php
namespace biz;

use database\DBFile;
use database\DBFolder;
use database\DbHelper;
use utils\SysTool;
use model\FileInf;
use utils\ConfigReader;
use utils\FileTool;
use utils\PathTool;
use utils\inc;

class FolderScaner extends FolderSchemaDB
{    
	function __construct() 
	{
	}

	var $m_cover = false;

    function save(/*FileInf*/$dir){
        $this->m_root = $dir;
        $this->m_files = array();
        $this->m_folders = array();
        $this->m_dirs = array();

        //解析结构文件.scheme.txt
        $lines = file($dir->schemaFile());
        foreach($lines as $line)
        {
            $file = new FileInf();
            $file->parseSchema($line);
            $file->uid = $this->m_root->uid;
            if($file->fdTask)
            {
                $this->m_folders[] = $file;
                $this->m_dirs[$file->pathSvr] = $file;
            }
            else{
                $this->m_files[] = $file;
            }
        }

        //分析
        $this->parseParent();
        $this->parseDirs();
        $this->updatePID();
        $this->updatePathRel();

        //删除根目录，根目录已经添加到数据库
        array_splice($this->m_folders,0,1);

        //覆盖同名项
        if($this->m_cover) $this->cover();
        
        //添加到目录表
        $fd = new DBFolder();
        $fd->addBatch($this->m_folders);

        //添加到文件表
        $df = new DBFile();
        $df->addBatch($this->m_files);
    }
}
?>